package com.you.shortlink.project.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.you.shortlink.project.dao.entity.LinkStatsTodayDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

/**
 * 短链接今日统计持久层
 */
public interface LinkStatsTodayMapper extends BaseMapper<LinkStatsTodayDO> {

    /**
     * 更新短链接今日统计信息
     */
    @Insert("""
            INSERT INTO t_link_stats_today (gid, full_short_url, date, today_pv, today_uv, today_uip, create_time, update_time, del_flag)
            VALUES (#{linkTodayStats.gid}, #{linkTodayStats.fullShortUrl}, #{linkTodayStats.date}, #{linkTodayStats.todayPv}, #{linkTodayStats.todayUv}, #{linkTodayStats.todayUip}, NOW(), NOW(), 0)
            ON DUPLICATE KEY UPDATE
            today_pv = today_pv + #{linkTodayStats.todayPv},
            today_uv = today_uv + #{linkTodayStats.todayUv},
            today_uip = today_uip + #{linkTodayStats.todayUip}
            """)
    void shortLinkTodayStats(@Param("linkTodayStats") LinkStatsTodayDO linkStatsTodayDO);

}
